package top.humbleyuan.double_pointer;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author HumbleYuan
 * @Date 2020/5/18 16:41
 * @Des 无重复字符的最长子串
 */
public class LeetCode_3 {
    public static void main(String[] args) {
        String s = "bacadef";
        String s1 = s;
        int maxLength = 0;
        Set<Character> set = new HashSet<>();
        int i=0,  j=0;

        while(i<s.length() && j<s.length()) {
            if(!set.contains(s1.charAt(j))){
                set.add(s1.charAt(j++));
                maxLength = Math.max(maxLength,set.size());
            }
            else
                set.remove(s1.charAt(i++));
        }
        System.out.println(maxLength);
    }
}
